package com.kofigyan.stateprogressbarsample.not_stateprogressbar.adapter;

import com.kofigyan.stateprogressbarsample.ResourceTable;
import com.kofigyan.stateprogressbarsample.not_stateprogressbar.utils.AbilityToAbility;
import com.kofigyan.stateprogressbarsample.not_stateprogressbar.utils.Constants;
import com.kofigyan.stateprogressbarsample.not_stateprogressbar.utils.Utils;
import ohos.app.Context;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class StatesListAdapter extends BaseListAdapter<String> {

    private List<String> items;
    private Context context;

    /**
     * 常规列表重写该方法
     *
     * @param context     context
     * @param list        数据源
     */
    public StatesListAdapter(Context context, List<String> list, boolean isDescending) {
        super(context, list, ResourceTable.Layout_item_states_list, new OnListItemClickListener<String>() {
            @Override
            public void onItemClick(String data, int position) {
                if (data.equals(Constants.ASCENDING)) {

                    Map<String, Object> params = new HashMap<>();
                    params.put(Constants.DESCENDING, false);
                    AbilityToAbility.toAbility(context,
                            Utils.selectActivity(position, Utils.allActivities), params);


                } else if (data.equals(Constants.DESCENDING)) {
                    Map<String, Object> params = new HashMap<>();
                    params.put(Constants.DESCENDING, true);
                    AbilityToAbility.toAbility(context,
                            Utils.selectActivity(position - 1, Utils.allActivities), params);
                } else {
                    AbilityToAbility.toAbility(context, Utils.selectActivity(position,
                            isDescending ? Utils.basicDescendingActivities : Utils.basicActivities));
                }
            }
        });
        this.context = context;
        this.items = list;
    }

    @Override
    public void onBindData(SuperViewHolder holder, int layoutPosition, String data) {
        holder.setText(ResourceTable.Id_tvTitle, data);
    }
}
